﻿<%@ WebHandler Language="C#" Class="admin" %>

using System;
using System.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;

public class admin : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        string cmd = context.Request.Form["cmd"];
        if (cmd=="adminlogin") {
            string pass = context.Request.Form["password"];
            if (pass == "adminpass")
            {
                context.Response.Write("ok");
                context.Response.End();
            }
            else
            {
                context.Response.Write("no");
                context.Response.End();
            }
            return;
        }
        if (cmd == "gettable")
        {
            DataTable tb = SQLHelper.GetTable("select uid,Round(convert(float,sum(zongfen)-max(zongfen)-min(zongfen))/(count(*)-2),2) as mark,max(zongfen) as zuida from pingfen group by uid having count(*)>2 and uid > 8");
            if(tb.Rows.Count>0){
                context.Response.Write(ConvertJson.ToJson(tb));
            }else{
                context.Response.Write("[]");
            }

            context.Response.End();
            return;
        }
        if (cmd == "gettable_judge")
        {
            DataTable tb = SQLHelper.GetTable("select uid,Round(convert(float,sum(zongfen)-max(zongfen)-min(zongfen))/(count(*)-2),2) as mark,max(zongfen) as zuida from pingfen_judge group by uid having count(*)>2 and uid > 8");
            if(tb.Rows.Count>0){
                context.Response.Write(ConvertJson.ToJson(tb));
            }else{
                context.Response.Write("[]");
            }

            context.Response.End();
            return;
        }
        if (cmd == "startfen")
        {
            string uid = context.Request.Form["uid"];
            SQLHelper.ExcuteSQL("update control set uid="+uid);
            context.Response.Write("已开启打分");
            context.Response.End();
            return;
        }
        if (cmd == "closefen")
        {
            string uid = context.Request.Form["uid"];
            SQLHelper.ExcuteSQL("update control set uid=0");
            context.Response.Write("已关闭打分");
            context.Response.End();
            return;
        }


    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}